import Cookies from 'js-cookie'

export function getCookie(key) {
  return Cookies.getJSON(key)
}

export function setCookie(key, value) {
  return Cookies.set(key, value)
}

export function removeCookie(key) {
  return Cookies.remove(key)
}
export function clearCookie(isClearLocalStorage) {

  Cookies.remove("tenant")
  Cookies.remove("tenantList")
  Cookies.remove("user")
  Cookies.remove("authTokenInfo")
  Cookies.remove("accessToken")
  localStorage.clear('sourceSinkData')
  // if (!isClearLocalStorage) {
  //   Cookies.remove("authToken")
  //   Cookies.remove("jwt")
  //   localStorage.clear('sourceSinkData')
  // }
}

/**
 * 存储localStorage
 */
export const setStore = (key, value) => {
  window.localStorage.setItem(key, value)
}
/**
 * 获取localStorage
 */
export const getStore = (key) => {
  var d = window.localStorage.getItem(key);
  if (!d) return d;
  return JSON.parse(d);
  // return window.localStorage.getItem(key)
}
/**
 * 删除localStorage
 */
export const removeStore = (key) => {
  window.localStorage.removeItem(key)
}

/**
 * 获取全部localStorage
 */
export const getAllStore = (params) => {
  const list = []
  const {
    type
  } = params
  for (let i = 1; i <= window.sessionStorage.length; i++) {
    if (type) {
      list.push({
        name: window.sessionStorage.key(i),
        content: getStore({
          name: window.sessionStorage.key(i),
          type: 'session'
        })
      })
    } else {
      list.push(getStore({
        name: window.localStorage.key(i),
        content: getStore({
          name: window.localStorage.key(i)
        })
      }))
    }
  }

  return list
}

/**
 * 清空全部localStorage
 */
export const clearStore = () => {
  window.localStorage.clear()
}
